import request from '@/axios';

export const getList = (current, size, params) => {
  return request({
    url: '/blade-iot/device/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
    }
  })
}

export const getTreeList = (parentId, params) => {
  return request({
    url: '/blade-iot/device/tree-list',
    method: 'get',
    params: {
      parentId,
      ...params,
    }
  })
}

export const getPage = (current, size, groupId) => {
  return request({
    url: '/blade-iot/device/page',
    method: 'get',
    params: {
      groupId,
      current,
      size,
    }
  })
}

export const getTable = (current, size, params) => {
  return request({
    url: '/blade-iot/device/group-select',
    method: 'get',
    params: {
      ...params,
      current,
      size,
    }
  })
}

export const getDetail = (id) => {
  return request({
    url: '/blade-iot/device/detail',
    method: 'get',
    params: {
      id
    }
  })
}

export const getDetails = (ids) => {
  return request({
    url: '/blade-iot/device/details',
    method: 'get',
    params: {
      ids
    }
  })
}

export const getDetailByName = (deviceName) => {
  return request({
    url: '/blade-iot/device/detail',
    method: 'get',
    params: {
      deviceName
    }
  })
}

export const remove = (ids) => {
  return request({
    url: '/blade-iot/device/remove',
    method: 'post',
    params: {
      ids,
    }
  })
}

export const add = (row) => {
  return request({
    url: '/blade-iot/device/submit',
    method: 'post',
    data: row
  })
}

export const update = (row) => {
  return request({
    url: '/blade-iot/device/submit',
    method: 'post',
    data: row
  })
}

export const select = (productKey) => {
  return request({
    url: '/blade-iot/device/select',
    method: 'get',
    params: {
      productKey
    }
  })
}

export const batchSubmit = (productKey, batchSize) => {
  return request({
    url: '/blade-iot/device/batch-submit',
    method: 'post',
    params: {
      productKey,
      batchSize
    }
  })
}

export const updateDeviceNoteName = (deviceId, deviceNoteName) => {
  return request({
    url: '/blade-iot/device/update-note-name',
    method: 'post',
    params: {
      deviceId,
      deviceNoteName
    }
  })
}

export const addSubsetDevice = (deviceId, parentId) => {
  return request({
    url: '/blade-iot/device/subset-submit',
    method: 'post',
    params: {
      deviceId,
      parentId
    }
  })
}

export const unbindSubsetDevice = (deviceId) => {
  return request({
    url: '/blade-iot/device/subset-unbind',
    method: 'post',
    params: {
      deviceId,
    }
  })
}

export const getTopicList = (productKey, deviceName) => {
  return request({
    url: '/blade-iot/device/topic',
    method: 'get',
    params: {
      productKey,
      deviceName,
    }
  })
}

export const getDeviceCount = (productKey) => {
  return request({
    url: '/blade-iot/device/device-count',
    method: 'get',
    params: {
      productKey
    }
  })
}
export const updateApi = (row) => {
  return request({
    url: '/proxy/blade-broker/device/mqtt/updateTheFirmware',
    method: 'post',
    data: row
  })
}
